<html>
<head><meta charset="utf-8"><title>unaligned memory access · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html">unaligned memory access</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="159062060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062060">(Feb 21 2019 at 12:05)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> memory accesses happen on a place, and a place consists of a pointer, a size, and an alignment. when you use a pointer to access memory, a (pointer)-value-to-place conversion occurs. at that point, the size and alignment of the place are determined with size_of_val and align_of_val. when the access later happens, and the pointer does not actually match the alignment given in the place, Miri detects UB.</p>



<a name="159062165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062165">(Feb 21 2019 at 12:07)</a>:</h4>
<p>So when one creates a reference from a pointer, we just check the reference validity, and that checks that the place it points to has the right alignment?</p>



<a name="159062236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062236">(Feb 21 2019 at 12:09)</a>:</h4>
<blockquote>
<p>when one creates a reference from a pointer, we just check the reference validity</p>
</blockquote>
<p>yes</p>
<blockquote>
<p>that checks that the place it points to has the right alignment?</p>
</blockquote>
<p>no, no place is involved there. we can just compare the pointer value with <code>align_of_val</code>.</p>



<a name="159062284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062284">(Feb 21 2019 at 12:10)</a>:</h4>
<p>I think I found a feature request for miri here. When dereferencing an unaligned pointer the error tells me the actual alignment of the place, and the value expected: "tried to access memory with alignment 8, but alignment 16 is required" but when I create an invalid reference it "just" tells me "type validation failed: encountered unaligned reference"</p>



<a name="159062297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062297">(Feb 21 2019 at 12:10)</a>:</h4>
<p>would be cool if that could also tell me the alignment required, and the alignment "provided"</p>



<a name="159062306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062306">(Feb 21 2019 at 12:10)</a>:</h4>
<p>re: what I originally said, actually currently we don't use <code>align_of_val</code> for ref-to-place conversions, we use the static alignment reflected in the type</p>



<a name="159062310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062310">(Feb 21 2019 at 12:10)</a>:</h4>
<blockquote>
<p>we can just compare the pointer value with align_of_val.</p>
</blockquote>
<p>Ah duh, yes, that makes sense.</p>



<a name="159062355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Carosone <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062355">(Feb 21 2019 at 12:11)</a>:</h4>
<p>I recall hearing about some system (maybe Java) that stashed flags in the low-order bits of &gt;byte-aligned pointers.</p>



<a name="159062356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062356">(Feb 21 2019 at 12:11)</a>:</h4>
<p>which is probably more reasonable because we can determine it statically. ultimately the expected alignment of a load must be known sttaically, after all.</p>



<a name="159062416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062416">(Feb 21 2019 at 12:12)</a>:</h4>
<blockquote>
<p>would be cool if that could also tell me the alignment required, and the alignment "provided"</p>
</blockquote>
<p>sure, make a bug report (this would be against rustc, that's part of the validation code that CTFE also uses)</p>



<a name="159062425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062425">(Feb 21 2019 at 12:12)</a>:</h4>
<p>Yes, but when allocating memory, some of the methods pass an alignment manually. E.g. when allocating a <code>[u8]</code>, I can choose the alignment</p>



<a name="159062436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062436">(Feb 21 2019 at 12:12)</a>:</h4>
<p>yes? what does that have to do with our discussion?</p>



<a name="159062450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062450">(Feb 21 2019 at 12:13)</a>:</h4>
<p>when you allocate a <code>[u16]</code> and you use alignment 1, you have UB by the rules I stated above</p>



<a name="159062454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062454">(Feb 21 2019 at 12:13)</a>:</h4>
<p><code>align_of_val</code> wouldnt know how you allocated that value anyway</p>



<a name="159062516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062516">(Feb 21 2019 at 12:14)</a>:</h4>
<p>All of this is obvious if one knows that miri has a linear memory region, and when one allocates with some alignment, then one gets a pointer whose address is aligned properly. I haven't thought about how that would be implemented till now, but it probably does not make sense to implement that in any other way.</p>



<a name="159062522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062522">(Feb 21 2019 at 12:14)</a>:</h4>
<p>I just thought that maybe, miri allocations where "disjoint" memory regions</p>



<a name="159062541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062541">(Feb 21 2019 at 12:15)</a>:</h4>
<p>so that if I allocate twice a [u8; 16], that I can't use a pointer to the first one to access the second region or something</p>



<a name="159062690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062690">(Feb 21 2019 at 12:18)</a>:</h4>
<p>but it suffice to remember which allocation each pointer was crated from, and then check on dereference that it points to somewhere inside that allocation</p>



<a name="159062841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062841">(Feb 21 2019 at 12:21)</a>:</h4>
<blockquote>
<p>miri has a linear memory region</p>
</blockquote>
<p>what do you mean by this?</p>



<a name="159062845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062845">(Feb 21 2019 at 12:21)</a>:</h4>
<blockquote>
<p>miri allocations where "disjoint" memory regions</p>
</blockquote>
<p>they are</p>



<a name="159062848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062848">(Feb 21 2019 at 12:21)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> this information, which allocation is associated to which pointer / reference, is not part of Stacked Borrows, right ?</p>



<a name="159062855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062855">(Feb 21 2019 at 12:22)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">@RalfJ</span> this information, which allocation is associated to which pointer / reference, is not part of Stacked Borrows, right ?</p>
</blockquote>
<p>correct, that's just miri's basic memory model</p>



<a name="159062903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062903">(Feb 21 2019 at 12:22)</a>:</h4>
<p>which is not necessarily the same as Rust's</p>



<a name="159062910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062910">(Feb 21 2019 at 12:22)</a>:</h4>
<p>so how is that checked ?</p>



<a name="159062918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159062918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159062918">(Feb 21 2019 at 12:22)</a>:</h4>
<p>does every pointer get an associated allocation, and that's propagated to all derived pointers /references ?</p>



<a name="159063017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159063017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159063017">(Feb 21 2019 at 12:24)</a>:</h4>
<p>maybe not even an allocation, maybe just some "bounds", e.g., pointer value + range of values that it can take, which is why the error happens when the pointer is offsetted, and not on dereference</p>



<a name="159069367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159069367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159069367">(Feb 21 2019 at 14:01)</a>:</h4>
<blockquote>
<p>so how is that checked ?</p>
</blockquote>
<p>it's less checked and  more by construction. sorry I dont have the time to explain the memory model right now.</p>



<a name="159069391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159069391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159069391">(Feb 21 2019 at 14:01)</a>:</h4>
<p>ideally I should explain it into a <code>.md</code> file anyway and put that somewhere. <span class="user-mention" data-user-id="124288">@oli</span> what would be a good place for a document explaining miri's memory model? the rustc guide? it is also used by CTFE, after all.</p>



<a name="159072583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159072583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159072583">(Feb 21 2019 at 14:44)</a>:</h4>
<p>yes, the guide is the idea place for this</p>



<a name="159072647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159072647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159072647">(Feb 21 2019 at 14:44)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> maybe pointing to the exact page from the miri front page might be helpful for interested parties, too</p>



<a name="159072951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159072951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159072951">(Feb 21 2019 at 14:48)</a>:</h4>
<p>In which aspect is this memory model relevant for Rust programmers ?</p>



<a name="159072973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159072973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159072973">(Feb 21 2019 at 14:49)</a>:</h4>
<p>to learn about memory models? :D and to understand how CTFE works</p>



<a name="159072978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159072978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159072978">(Feb 21 2019 at 14:49)</a>:</h4>
<p>As in, it might be better to document it in the miri repo, and link it / include it, in the rustc-guide and other document</p>



<a name="159072999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159072999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159072999">(Feb 21 2019 at 14:49)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> if my code is correct according to miri's memory model, is it also correct in x86 ?</p>



<a name="159073081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073081">(Feb 21 2019 at 14:50)</a>:</h4>
<p>or in other words, is the intent to make miri's memory model the memory model that all rust programs should adhere to ?</p>



<a name="159073179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073179">(Feb 21 2019 at 14:51)</a>:</h4>
<p>note that Rust's memory model is even further from x86 than from Miri's</p>



<a name="159073235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073235">(Feb 21 2019 at 14:52)</a>:</h4>
<p>but the intent is for Miri's model to be a sound approximation of Rust's model, yes</p>



<a name="159073266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073266">(Feb 21 2019 at 14:52)</a>:</h4>
<p>as in, every program defined in Miri's model should be defined in Rust's model</p>



<a name="159073281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073281">(Feb 21 2019 at 14:52)</a>:</h4>
<p>So I think that should be its own document, with the intent that it will be RFC'ed at some point</p>



<a name="159073300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073300">(Feb 21 2019 at 14:52)</a>:</h4>
<p>there are some hard questions there about transmuting pointers to integers, but let's ignore those</p>



<a name="159073317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073317">(Feb 21 2019 at 14:53)</a>:</h4>
<p>I dont think it needs RFC'ing, it's a compiler implementation detail</p>



<a name="159073322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073322">(Feb 21 2019 at 14:53)</a>:</h4>
<p>maybe even in the UCG repo, just like stacked borrows, as documentation for now of what miri does</p>



<a name="159073328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073328">(Feb 21 2019 at 14:53)</a>:</h4>
<p>the Rust memory model needs RFC'ing</p>



<a name="159073333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073333">(Feb 21 2019 at 14:53)</a>:</h4>
<p>but it first needs a paper, because it's that far out there^^</p>



<a name="159073421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073421">(Feb 21 2019 at 14:54)</a>:</h4>
<p>so the programs that miri's model will accept is a subset of the one that rust memory model accepts ?</p>



<a name="159073435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073435">(Feb 21 2019 at 14:54)</a>:</h4>
<p>hopefully</p>



<a name="159073476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073476">(Feb 21 2019 at 14:55)</a>:</h4>
<p>and moreover, if a program gets accepted by both it has the same behavior (that might seem obvious but it isnt^^)</p>



<a name="159073510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073510">(Feb 21 2019 at 14:55)</a>:</h4>
<p>so I think that would be a language feature worth guaranteeing, but anyways, I'm digressing, any place is fine for me as long as it gets written down somewhere at some point.</p>



<a name="159073999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159073999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159073999">(Feb 21 2019 at 15:00)</a>:</h4>
<p>it is certainly worth guaranteeing, but it may be really, really hard</p>



<a name="159074011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074011">(Feb 21 2019 at 15:00)</a>:</h4>
<p>and the Miri model should also be relatively simple</p>



<a name="159074064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074064">(Feb 21 2019 at 15:01)</a>:</h4>
<p>like, one example of a case where we currently don't achieve this is that when you compare two pointers into different objects, they will never be equal. but in reality, if two objects are allocated right next to each other, a pointer to the end of one object might compare equal to a pointer to the beginning of another.</p>



<a name="159074088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074088">(Feb 21 2019 at 15:01)</a>:</h4>
<p>we could restrict the comparisons we allow in Miri's model, but that means programs will stop working that really should work</p>



<a name="159074223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074223">(Feb 21 2019 at 15:02)</a>:</h4>
<blockquote>
<p>like, one example of a case where we currently don't achieve this is that when you compare two pointers into different objects, they will never be equal. but in reality, if two objects are allocated right next to each other, a pointer to the end of one object might compare equal to a pointer to the beginning of another.</p>
</blockquote>
<p>I thought that this was undefined behavior.</p>



<a name="159074303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074303">(Feb 21 2019 at 15:03)</a>:</h4>
<p>no, both C and C++ allow this (but C++ is vague about what the result is)</p>



<a name="159074336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074336">(Feb 21 2019 at 15:04)</a>:</h4>
<p>this is related to the special exception for the pointer "right at the end" (often called one-past-the-end) of an allocation</p>



<a name="159074414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074414">(Feb 21 2019 at 15:04)</a>:</h4>
<p>i don't recall it that way, i recall that the behavior of comparing pointers originating from different allocations is undefined</p>



<a name="159074554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074554">(Feb 21 2019 at 15:06)</a>:</h4>
<p>nope, you are mistaken</p>



<a name="159074563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074563">(Feb 21 2019 at 15:06)</a>:</h4>
<p>(I am talking about <code>==</code> and <code>!=</code> comparison)</p>



<a name="159074566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074566">(Feb 21 2019 at 15:06)</a>:</h4>
<p>that is, if you have a pointer to an [u8; N] array, you can use that pointer, and pointers derived from it, to refer to elements in the array, and one past the end, but if you allocate two [u8; N] arrays, you can't use a pointer to an element of the first array to access an element of the second. If the "one-past-the-end" pointer of the first array, happens to have the same address as the first element of the second array, those two pointers are allowed to compare differently, even though they have the same address</p>



<a name="159074584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074584">(Feb 21 2019 at 15:06)</a>:</h4>
<p>you can't use the pointer to <em>access</em> the other side</p>



<a name="159074596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074596">(Feb 21 2019 at 15:06)</a>:</h4>
<p>but we talked about <em>comparing pointers</em></p>



<a name="159074599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074599">(Feb 21 2019 at 15:06)</a>:</h4>
<p>different thing</p>



<a name="159074623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074623">(Feb 21 2019 at 15:07)</a>:</h4>
<p>the access is UB, the comparison is not</p>



<a name="159074640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074640">(Feb 21 2019 at 15:07)</a>:</h4>
<p>i thought the comparison was also UB</p>



<a name="159074642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074642">(Feb 21 2019 at 15:07)</a>:</h4>
<p>in C, the comparison must "compare the physical representations of the pointer" (but really compilers ignore that), in C++ they say something about the result being unspecified or so</p>



<a name="159074670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074670">(Feb 21 2019 at 15:08)</a>:</h4>
<p>hmm</p>



<a name="159074713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074713">(Feb 21 2019 at 15:08)</a>:</h4>
<p>so the comparison is defined behavior but they may either compare equal or not</p>



<a name="159074739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074739">(Feb 21 2019 at 15:08)</a>:</h4>
<p>whether comparing them multiple times must yield consistent result is unknown (as usual in C/C++...)</p>



<a name="159074765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074765">(Feb 21 2019 at 15:09)</a>:</h4>
<p>well actually in C it must yield consistent results, the standard permits no non-determinism</p>



<a name="159074767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074767">(Feb 21 2019 at 15:09)</a>:</h4>
<p>in C++ it's unclear</p>



<a name="159074782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159074782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159074782">(Feb 21 2019 at 15:09)</a>:</h4>
<p>and anyway LLVM implements the C++ version even for C</p>



<a name="159075001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075001">(Feb 21 2019 at 15:12)</a>:</h4>
<p><a href="http://eel.is/c++draft/expr.eq#3.1" target="_blank" title="http://eel.is/c++draft/expr.eq#3.1">http://eel.is/c++draft/expr.eq#3.1</a></p>



<a name="159075019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075019">(Feb 21 2019 at 15:12)</a>:</h4>
<p>So the result is unspecified.</p>



<a name="159075160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075160">(Feb 21 2019 at 15:14)</a>:</h4>
<p>That is, the comparison is allowed to happen, but the result can be anything.</p>



<a name="159075327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075327">(Feb 21 2019 at 15:16)</a>:</h4>
<p>well, it can be true or false</p>



<a name="159075349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075349">(Feb 21 2019 at 15:16)</a>:</h4>
<p>but I read this as requiring a valid boolean, i.e., using this is a conditional <em>is</em> allowed</p>



<a name="159075388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075388">(Feb 21 2019 at 15:17)</a>:</h4>
<p>yes, but what miri does (returning always false) is ok according to this</p>



<a name="159075408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075408">(Feb 21 2019 at 15:17)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">@RalfJ</span> maybe pointing to the exact page from the miri front page might be helpful for interested parties, too</p>
</blockquote>
<p>for now I opened an issue: <a href="https://github.com/rust-lang/rust/issues/58618" target="_blank" title="https://github.com/rust-lang/rust/issues/58618">https://github.com/rust-lang/rust/issues/58618</a></p>



<a name="159075470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075470">(Feb 21 2019 at 15:18)</a>:</h4>
<p>I have this on my list, but it's quite far down (I think a basic spec of MIR <em>without</em> the memory model is more important), so that shouldnt block anyone else from giving it a shot</p>



<a name="159075497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075497">(Feb 21 2019 at 15:18)</a>:</h4>
<p>true, but I deliberately said the behavior is the <em>same</em> in both models</p>



<a name="159075504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075504">(Feb 21 2019 at 15:18)</a>:</h4>
<p>reading this part of the C++ standard, i cannot but think that none of this makes much sense as is if you have ZSTs in the language (which C and C++ don't have), then you have many objects at the same address</p>



<a name="159075510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075510">(Feb 21 2019 at 15:18)</a>:</h4>
<p>and if one model allows true/false, and the other always makes it true, that's not the same behavior</p>



<a name="159075550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075550">(Feb 21 2019 at 15:19)</a>:</h4>
<p>well, with ZSTs the pointer is always one-past-the-end</p>



<a name="159075554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075554">(Feb 21 2019 at 15:19)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> to make the behavior the same in both models, we can just make it undefined</p>



<a name="159075556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075556">(Feb 21 2019 at 15:19)</a>:</h4>
<p>so they all may compare arbitarily</p>



<a name="159075643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075643">(Feb 21 2019 at 15:20)</a>:</h4>
<p>so the comparison itself wouldn't return false on miri, but be an error, and when targetting something else, anything can happen</p>



<a name="159075651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075651">(Feb 21 2019 at 15:20)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">@RalfJ</span> to make the behavior the same in both models, we can just make it undefined</p>
</blockquote>
<p>so you want to make <code>ptr::eq</code> on ZSTs UB? I dont think that'll make people happy^^</p>



<a name="159075663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075663">(Feb 21 2019 at 15:20)</a>:</h4>
<p>oh you mean undefined in Miri only</p>



<a name="159075673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075673">(Feb 21 2019 at 15:20)</a>:</h4>
<p>yes we could. but Miri is also supposed to be <em>useful</em>...</p>



<a name="159075678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075678">(Feb 21 2019 at 15:20)</a>:</h4>
<p>i think that if we are going to adopt similar semantics to C++, we need to handle ZSTs differently anyways</p>



<a name="159075726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075726">(Feb 21 2019 at 15:21)</a>:</h4>
<p>ptr comparison has nothing to do with types, but I assume you mean zero-sized allocations</p>



<a name="159075733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075733">(Feb 21 2019 at 15:21)</a>:</h4>
<p>(which we do have, e.g. from ZST statics)</p>



<a name="159075744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075744">(Feb 21 2019 at 15:21)</a>:</h4>
<p>like two pointers with the same address to ZSTs, are they pointing their objects? their objects _and_ one past the end? their object and all other objects in that address? etc.</p>



<a name="159075761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075761">(Feb 21 2019 at 15:21)</a>:</h4>
<p>there's no object^^</p>



<a name="159075768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075768">(Feb 21 2019 at 15:21)</a>:</h4>
<p><code>4</code> is a valid pointer to a <code>[u32; 0]</code></p>



<a name="159075838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075838">(Feb 21 2019 at 15:22)</a>:</h4>
<p>there is a value</p>



<a name="159075849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075849">(Feb 21 2019 at 15:22)</a>:</h4>
<p>there's a pointer value</p>



<a name="159075854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075854">(Feb 21 2019 at 15:22)</a>:</h4>
<p>but no pointed-to value</p>



<a name="159075859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075859">(Feb 21 2019 at 15:22)</a>:</h4>
<p>in the language/machine</p>



<a name="159075882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075882">(Feb 21 2019 at 15:22)</a>:</h4>
<p>ZSTs are a fiction</p>



<a name="159075923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159075923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159075923">(Feb 21 2019 at 15:23)</a>:</h4>
<p>I think trying to make them actually exist in the memory model will make that model a lot more complicated, for no gain at all</p>



<a name="159076025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076025">(Feb 21 2019 at 15:24)</a>:</h4>
<p>i'm not suggesting that, just saying that the memory model will need to explain what happens with zero-sized allocations, ZST values, etc. somewhere</p>



<a name="159076092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076092">(Feb 21 2019 at 15:25)</a>:</h4>
<p>even if that is, a ZST value can have any address, addresses to ZST values of the same type always compare equally / different / are not comparable at all, etc.</p>



<a name="159076095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076095">(Feb 21 2019 at 15:25)</a>:</h4>
<p>zero-sized allocations, yes. they are just allocations with size 0 though and should not get any special treatment.<br>
ZST, no. they just dont show up any more. the memory model doesnt care about types.</p>



<a name="159076120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076120">(Feb 21 2019 at 15:25)</a>:</h4>
<p>there's no such thing as a ZST value, at the language semantics level</p>



<a name="159076207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076207">(Feb 21 2019 at 15:26)</a>:</h4>
<p>i thought that <code>Box&lt;ZST&gt;</code> performed a zero-sized allocation, returning a pointer, and that pointer was the address of the value of that type</p>



<a name="159076233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076233">(Feb 21 2019 at 15:26)</a>:</h4>
<p><code>Box&lt;ZST&gt;</code> returns <code>align_of::&lt;ZST&gt;</code></p>



<a name="159076238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076238">(Feb 21 2019 at 15:26)</a>:</h4>
<p>no allocation happens</p>



<a name="159076262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076262">(Feb 21 2019 at 15:26)</a>:</h4>
<p>that's how it is implemented, is that the operational semantics for allocating a ZST ?</p>



<a name="159076263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076263">(Feb 21 2019 at 15:26)</a>:</h4>
<p>but there are ways to get an actual zero-sized allocation, such as <code>static FOO: ZST</code></p>



<a name="159076291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076291">(Feb 21 2019 at 15:27)</a>:</h4>
<p>from the memory model perspective you dont allocate a type but a size/alignment. and sure, the size can be 0. so what?</p>



<a name="159076296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076296">(Feb 21 2019 at 15:27)</a>:</h4>
<p>If I do GlobalAlloc::alloc(Layout&lt;ZST&gt;) -&gt; *mut u8, can I do *ptr = ZST() ?</p>



<a name="159076318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076318">(Feb 21 2019 at 15:27)</a>:</h4>
<p>the GlobalAlloc contract says you are not allowed to use it with size 0</p>



<a name="159076373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076373">(Feb 21 2019 at 15:28)</a>:</h4>
<p>but you are also jumping around between lots of different topics here^^</p>



<a name="159076431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076431">(Feb 21 2019 at 15:29)</a>:</h4>
<p><code>*ptr = ZST</code> is a zero-sized memory access, which does not actually do anything in memory (but it should check alignment, which Miri currently does not implement correctly)</p>



<a name="159076518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076518">(Feb 21 2019 at 15:30)</a>:</h4>
<p>I would prefer a programming language in which ZST don't need to be handled exceptionally</p>



<a name="159076577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076577">(Feb 21 2019 at 15:30)</a>:</h4>
<p>I know this is how things are currently implemented, but I always assumed that these were implementation details.</p>



<a name="159076594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076594">(Feb 21 2019 at 15:30)</a>:</h4>
<p>well, just go look at the slice iterator or <code>Box</code> source code. in Rust, they do need special treatment.</p>



<a name="159076661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076661">(Feb 21 2019 at 15:31)</a>:</h4>
<p>and in the model, zero-sized <em>accesses</em> (the types dont matter) <em>are</em> special in the sense that they dont actually require there to be a valid allocation anywhere</p>



<a name="159076682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076682">(Feb 21 2019 at 15:31)</a>:</h4>
<p>In this particular implementation of the standard library they need special treatment, but whether it is necessary to leak that special treatment to users is a different issue</p>



<a name="159076727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076727">(Feb 21 2019 at 15:32)</a>:</h4>
<p>we could say that they do, but then a whole lot of existing code has UB</p>



<a name="159076731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076731">(Feb 21 2019 at 15:32)</a>:</h4>
<p>so we likely don't want that</p>



<a name="159076766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076766">(Feb 21 2019 at 15:32)</a>:</h4>
<p>well, we can either have a special clause for empty accesses, or make a lot of existing code (in libstd and most likely elsewhere) UB.</p>



<a name="159076782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076782">(Feb 21 2019 at 15:32)</a>:</h4>
<p>I dont see a third way.</p>



<a name="159076804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076804">(Feb 21 2019 at 15:33)</a>:</h4>
<p>also note that the special case is rather tiny, it's one early return in the code for reads and writes</p>



<a name="159076877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076877">(Feb 21 2019 at 15:33)</a>:</h4>
<p>The third way would be ZSTs are not special, and code that users can write today that's guaranteed to work still does not have UB</p>



<a name="159076947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076947">(Feb 21 2019 at 15:34)</a>:</h4>
<p>you cant just axiomatize that, you have to make it happen in the model</p>



<a name="159076956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076956">(Feb 21 2019 at 15:34)</a>:</h4>
<p>I don't think that's possible</p>



<a name="159076972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076972">(Feb 21 2019 at 15:34)</a>:</h4>
<p>if a user is avoiding Box&lt;ZST&gt; and is just using *mut ptr = align_of&lt;ZST&gt;(), and relying that the addresses match, then that code might have UB, but that's not something that we are guaranteeing</p>



<a name="159076988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159076988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159076988">(Feb 21 2019 at 15:34)</a>:</h4>
<p>and again, it's not the zero-sized <em>types</em> that are special, it's the <em>accesses</em></p>



<a name="159077064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077064">(Feb 21 2019 at 15:35)</a>:</h4>
<blockquote>
<p>if a user is avoiding Box&lt;ZST&gt; and is just using *mut ptr = align_of&lt;ZST&gt;(), and relying that the addresses match, then that code might have UB, but that's not something that we are guaranteeing</p>
</blockquote>
<p>addresses match? we are talking about accesses, not ptr comparison!</p>



<a name="159077084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077084">(Feb 21 2019 at 15:35)</a>:</h4>
<p>I thought that we were also talking about pointers to ZSTs and whether comparing the pointers is allowed or not</p>



<a name="159077091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077091">(Feb 21 2019 at 15:35)</a>:</h4>
<p><code>let x = *Box::new(ZST)</code> is UB without that special clause</p>



<a name="159077148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077148">(Feb 21 2019 at 15:36)</a>:</h4>
<p>because you are doing a memory access to address <code>1</code></p>



<a name="159077152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077152">(Feb 21 2019 at 15:36)</a>:</h4>
<p>and why would there be an allocation there</p>



<a name="159077183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077183">(Feb 21 2019 at 15:36)</a>:</h4>
<p><em>comparing pointers does not care about the type</em> (I said that above, hence the emphasis...)</p>



<a name="159077229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077229">(Feb 21 2019 at 15:37)</a>:</h4>
<p>that is not doing a memory access at address 1, that's reading 0 memory from address 1, which is a <code>nop</code></p>



<a name="159077259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077259">(Feb 21 2019 at 15:37)</a>:</h4>
<p>you just dclared zero-siozed accesses a special case</p>



<a name="159077262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077262">(Feb 21 2019 at 15:37)</a>:</h4>
<p>by making them a NOP</p>



<a name="159077279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077279">(Feb 21 2019 at 15:37)</a>:</h4>
<p>you said above you didnt want that</p>



<a name="159077283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077283">(Feb 21 2019 at 15:37)</a>:</h4>
<p>please make up your mind</p>



<a name="159077340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077340">(Feb 21 2019 at 15:38)</a>:</h4>
<p>i don't know why this is turning violent, but this is not what I said</p>



<a name="159077370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077370">(Feb 21 2019 at 15:38)</a>:</h4>
<p>I am just getting frustrated because I feel like you keep ignoring what I am saying.</p>



<a name="159077396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077396">(Feb 21 2019 at 15:38)</a>:</h4>
<p>so lets fall back</p>



<a name="159077401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077401">(Feb 21 2019 at 15:38)</a>:</h4>
<p>also I should get some work done today, and this already took too much time -- sorry</p>



<a name="159077436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077436">(Feb 21 2019 at 15:39)</a>:</h4>
<p>ok, better to do this some other time</p>



<a name="159077460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077460">(Feb 21 2019 at 15:39)</a>:</h4>
<p>once we have some actual models written down, I can point at the special casing in accesses and the absence of special casing in ptr comparison</p>



<a name="159077468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077468">(Feb 21 2019 at 15:39)</a>:</h4>
<p>and then we have a concrete ground for this discussion</p>



<a name="159077480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077480">(Feb 21 2019 at 15:39)</a>:</h4>
<p>currently we likely are working under very different assumptions, hence the furstration</p>



<a name="159077544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077544">(Feb 21 2019 at 15:40)</a>:</h4>
<p>i feel that when you talk about access and i talk about access we are referring to different things</p>



<a name="159077549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077549">(Feb 21 2019 at 15:40)</a>:</h4>
<p>so that sounds like a good idea</p>



<a name="159077637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077637">(Feb 21 2019 at 15:41)</a>:</h4>
<p>gosh I wish I could just have a pipe from my brain to a markdown file to be able to communicate the framework I am working in here^^</p>



<a name="159077645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077645">(Feb 21 2019 at 15:41)</a>:</h4>
<p>typing all of that up is <em>so slow</em></p>



<a name="159077719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077719">(Feb 21 2019 at 15:42)</a>:</h4>
<p>or just do a brain transfer to you :P</p>



<a name="159077726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077726">(Feb 21 2019 at 15:42)</a>:</h4>
<p>if that happens some day, it will be powered by Rust</p>



<a name="159077731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077731">(Feb 21 2019 at 15:42)</a>:</h4>
<p>:D</p>



<a name="159077752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned%20memory%20access/near/159077752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/unaligned.20memory.20access.html#159077752">(Feb 21 2019 at 15:42)</a>:</h4>
<p>and all this things will make sure that you don't pipe the wrong things out of your brain :P</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>